package com.action;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.util.DB;
import com.model.*;


public class searching extends ActionSupport

{

	ResultSet res,res1,res2;
	String catname=null;
	ArrayList<String> category=new ArrayList<String>();
	ArrayList<String> subcategory=new ArrayList<String>();
	
	public ArrayList<String> getSubcategory() {
		return subcategory;
	}

	public void setSubcategory(ArrayList<String> subcategory) {
		this.subcategory = subcategory;
	}

	public ArrayList<String> getCategory() {
		return category;
	}

	public void setCategory(ArrayList<String> category) {
		this.category = category;
	}

	public String execute()throws Exception
	{
		
		String query="select * from category;";
		res=DB.readFromBmtcDB(query);
		
		while(res.next())
		{
			
		   catname=res.getString("catname");
		   category.add(catname);
		   
		}
		
		
		System.out.println("The categories are"+category);
		
		return "success";
	}
	
	
	public ArrayList<String> categorylist()throws Exception
	{
		
		String query="select * from category;";
		res=DB.readFromBmtcDB(query);
		
		while(res.next())
		{
			
		   catname=res.getString("catname");
		   category.add(catname);
		   
		}
		return category;
		
		
	}
	
	public String sellerbrowse()throws Exception
	{
		Map session;
		session=ActionContext.getContext().getSession();
		String query="select * from category;";
		res=DB.readFromBmtcDB(query);
		
		while(res.next())
		{
			
		   catname=res.getString("catname");
		   int catid=res.getInt("catid");
		   category.add(catname);
		   session.put("category",category);
		   
		   String query1="select * from subcategory where catid="+catid+";";
		   res1=DB.readFromBmtcDB(query1);
			
			while(res1.next())
			{
				
				String subcatname=res1.getString("subcatname");
				subcategory.add(subcatname);
				
			}
			
		   
		   
		}
		
		System.out.println("The categories are"+category);
		
	
		 
		
		
	
		
		
		return "success";
		
	}
}
